package hotel.action;

import hotel.service.IRoomStyleService;
import java.io.IOException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import common.action.BaseAction;
import common.pojo.RoomStyle;
import common.utils.Page;
import common.utils.PageUtil;
import common.utils.PaginationUtil;

import static common.utils.Constants.*;

@Scope("prototype")
@Controller("roomStyleAction")
public class RoomStyleAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	/**
	 * 分页查询
	 * @return
	 * @throws Exception
	 */
	public String getRoomStyleListByPage() throws Exception {
		String currentTmp = request.getParameter("current");
		String where =" isDelete=0";
		Page page = getPage(currentTmp, where);
		roomStyleList = roomStyleService.find(page.getBeginIndex(), LIMIT, " sort desc, id asc", where);
		pagination = PaginationUtil.getPaginationStyleTwo(page,"getRoomStyleListByPage.action");
		return "roomStyleListByPage";
	}
	//
	public String getDeleteRoomStyleListByPage() throws Exception {
		String currentTmp = request.getParameter("current");
		String where =" isDelete=1";
		Page page = getPage(currentTmp, where);
		roomStyleList = roomStyleService.find(page.getBeginIndex(), LIMIT, " sort desc, id asc", where);
		pagination = PaginationUtil.getPaginationStyleTwo(page,"getDeleteRoomStyleListByPage.action");
		return "deleteRoomStyleListByPage";
	}
	
	public Page getPage(String currentTmp, String where) {
		int total = roomStyleService.getCount(where);
		int current = PageUtil.getCurrent(currentTmp);
		Page page = PageUtil.createPage(LIMIT, total, current);
		return page;
	}
	
	/**
	 * 新建
	 * @return
	 */	
	public String save(){		
		roomStyleService.save(roomStyle);
		return SUCCESS;
	}


	/**
	 * 根据id查找信息
	 * @return
	 */
	public String findInfoById(){
		int id= Integer.valueOf(request.getParameter("id"));
		roomStyle=roomStyleService.findInfoById(id);
		return "findSuccess";
	}


	/**
	 * 更新
	 * @return
	 */
	public String update(){
		roomStyleService.update(roomStyle);
		setUrl("panel/hotel/roomStyle/getRoomStyleListByPage.action");
		return SUCCESS;
	}
	

	public String deleteByIds(){
		String ids=request.getParameter("ids");
		roomStyleService.delete(ids);
		return SUCCESS;	
		
	}
	public String restoreByIds(){
		String ids=request.getParameter("ids");
		roomStyleService.restore(ids);
		return SUCCESS;	
		
	}
	
	public String completeDeleteByIds(){
		String ids=request.getParameter("ids");
		roomStyleService.completeDelete(ids);
		return SUCCESS;	
		
	}

	public String sort() throws IOException {
		String[] ids=request.getParameterValues("id");
		String[] sorts=request.getParameterValues("sort");
		roomStyleService.update(ids,sorts);
		return SUCCESS;
	}
	
	
	
	
	@Autowired
	private IRoomStyleService roomStyleService;
	
	private List<RoomStyle> roomStyleList;
	private String pagination;
	private RoomStyle roomStyle;

	public RoomStyle getRoomStyle() {
		return roomStyle;
	}

	public void setRoomStyle(RoomStyle roomStyle) {
		this.roomStyle = roomStyle;
	}

	public String getPagination() {
		return pagination;
	}

	public void setPagination(String pagination) {
		this.pagination = pagination;
	}

	public List<RoomStyle> getRoomStyleList() {
		return roomStyleList;
	}

	public void setRoomStyleList(List<RoomStyle> roomStyleList) {
		this.roomStyleList = roomStyleList;
	}

}
